package com.woniuxy.trade.controller;

import com.woniuxy.common.dto.RoomUserDto;
import com.woniuxy.common.result.Result;
import com.woniuxy.common.result.enums.impl.BusinessCode;
import com.woniuxy.trade.service.BuyerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
public class BuyerController {
    @Autowired
    BuyerService buyerService;

    /**
     * 用户参与竞拍
     */
    @PostMapping("/buyer/bid")
    @ApiOperation("用户参与竞拍")
    public Result offerBid(@RequestBody @Valid RoomUserDto roomUserDto){
        buyerService.offerBid(roomUserDto);
        return Result.ok();
    }
    /**
     * 缴纳保证金
     */
    @PostMapping("/buyer/payDeposit")
    @ApiOperation("用户缴纳保证金")
    public Result payDeposit(@RequestBody @Valid RoomUserDto roomUserDto){
        buyerService.payDeposit(roomUserDto);
        return Result.ok();
    }
    /**
     * 检查中间表是否有竞拍资格
     */
    @GetMapping("/buyer/havingDep")
    @ApiOperation("检查用户是否有资格竞拍")
    public Result havingDep(int roomid){
        Boolean f = buyerService.havingDep(roomid);
        if (f){
            return Result.ok();
        }else {
            return Result.fail(BusinessCode.NOT_Eligible_ERR);
        }
    }
    /**
     * 查看房间是否可以竞价
     */
    @GetMapping("/buyer/isTime")
    @ApiOperation("查看房间是否可以竞价")
    public Result isTime(int roomid){
        buyerService.isTime(roomid);
        return Result.ok();
    }
}
